package com.zzzzzz.app.topic.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zzzzzz.app.topic.NoSuchCommentException;
import com.zzzzzz.app.topic.dao.CommentDao;
import com.zzzzzz.app.topic.model.bo.CommentBo;
import com.zzzzzz.app.topic.model.po.Comment;
import com.zzzzzz.core.exception.SystemException;

@Service
public class CommentManager {

	@Resource
	private CommentDao commentDao;
	
	public Comment add(Comment comment) throws SystemException {
		return commentDao.add(comment);
	}
	
	public Comment add(Long userId, Long topicId, String content, Date createDate, Long parentId) throws SystemException {
		Comment comment = new Comment();
		comment.setTopicId(topicId);
		comment.setContent(content);
		comment.setCloseStatus(false);
		comment.setUserId(userId);
		comment.setCreateDate(createDate);
		comment.setParentId(parentId);
		return commentDao.add(comment);
	}
	
	public void delete(Long commentId) throws SystemException {
		commentDao.delete(commentId);
	}
	
	public Comment findById(Long id) throws NoSuchCommentException, SystemException {
		return commentDao.findById(id);
	}

	public int findCountByParentId(Long parentId) throws SystemException {
		return commentDao.findCountByParentId(parentId);
	}

	public List<Comment> findAllCommentsByParentId(long parentId) throws SystemException {
		return commentDao.findAllCommentsByParentId(parentId);
	}

	public List<CommentBo> findCommentBoListByParentId(long parentId, boolean ascending, int start, int offset) throws NoSuchCommentException, SystemException {
		return commentDao.findCommentBoListByParentId(parentId, ascending, start, offset);
	}

	public int findCountByTopicId(Long topicId) throws SystemException {
		return commentDao.findCountByTopicId(topicId);
	}

	public List<CommentBo> findByTopicId(long topicId, boolean pAscending, int pStart, int pOffset, boolean cAscending, 
		int cStart, int cOffset) throws SystemException {
		return commentDao.findByTopicId(topicId, pAscending, pStart, pOffset, cAscending, cStart, cOffset);
	}

}
